//package com.yu8home.opcua.test;
//
//import lombok.extern.slf4j.Slf4j;
//import org.eclipse.milo.examples.client.ClientExample;
//import org.eclipse.milo.examples.client.ClientExampleRunner;
//import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
//import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
//import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
//import org.eclipse.milo.opcua.stack.core.AttributeId;
//import org.eclipse.milo.opcua.stack.core.Identifiers;
//import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
//import org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject;
//import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
//import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
//import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
//import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode;
//import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
//import org.eclipse.milo.opcua.stack.core.types.structured.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.util.List;
//import java.util.concurrent.CompletableFuture;
//import java.util.concurrent.atomic.AtomicInteger;
//import java.util.concurrent.atomic.AtomicLong;
//
//import static com.google.common.collect.Lists.newArrayList;
//import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
//
//@Slf4j
//public class E {
//
//    public static void main(String[] args) throws Exception {
//        E example = new E();
//        new ClientExampleRunner(example, true).run();
//    }
//
//    private final Logger logger = LoggerFactory.getLogger(getClass());
//
//    private final AtomicLong clientHandles = new AtomicLong(1L);
//
//    @Override
//    public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
//        Conn.getConnect();
//
//
//        // synchronous connect
//        client.connect().get();
//
//        // create a subscription and a monitored item
//        UaSubscription subscription = client.getSubscriptionManager().createSubscription(1000.0).get();
//
//        NodeId nodeId = new NodeId(2, "_CustomAlarms.k");
//
//
//        DataValue dataValue = Conn.opcUaClient.readValue(0.0, TimestampsToReturn.Neither, nodeId).get();
//        log.info("当前线程名：{}，{} = {}，耗时：{}", Thread.currentThread().getName(), dataValue.getValue().getValue());
//
//
//        ReadValueId readValueId = new ReadValueId(
//                nodeId,
//                //   Identifiers.Server,
//                AttributeId.EventNotifier.uid(), null, QualifiedName.NULL_VALUE);
//
////        ReadValueId readValueId = new ReadValueId(
////            Identifiers.Server,
////            AttributeId.EventNotifier.uid(),
////            null,
////            QualifiedName.NULL_VALUE
////        );
//
//        // client handle must be unique per item
//        UInteger clientHandle = uint(clientHandles.getAndIncrement());
//
//        EventFilter eventFilter = new EventFilter(new SimpleAttributeOperand[]{new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[]{new QualifiedName(0, "EventId")}, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[]{new QualifiedName(0, "EventType")}, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[]{new QualifiedName(0, "SourceNode")}, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[]{new QualifiedName(0, "SourceName")}, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[]{new QualifiedName(0, "Severity")}, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[]{new QualifiedName(0, "Time")}, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[]{new QualifiedName(0, "Message")}, AttributeId.Value.uid(), null)}, new ContentFilter(null));
//
//        MonitoringParameters parameters = new MonitoringParameters(clientHandle, 0.0, ExtensionObject.encode(client.getStaticSerializationContext(), eventFilter), uint(10), true);
//
//        MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(readValueId, MonitoringMode.Reporting, parameters);
//
//        List<UaMonitoredItem> items = subscription.createMonitoredItems(TimestampsToReturn.Both, newArrayList(request)).get();
//
//        // do something with the value updates
//        UaMonitoredItem monitoredItem = items.get(0);
//
//        final AtomicInteger eventCount = new AtomicInteger(0);
//
//        monitoredItem.setEventConsumer((item, vs) -> {
//            NodeId nodeId2 = item.getReadValueId().getNodeId();
//            logger.info("事件来源：{} === {}", nodeId2, nodeId2.getIdentifier().toString());
//
//            for (int i = 0; i < vs.length; i++) {
//                logger.info("\tvariant[{}]: {}", i, vs[i].getValue());
//            }
//
//            if (eventCount.incrementAndGet() == 3) {
//                future.complete(client);
//            }
//        });
//    }
//
//}
